package com.control;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;

import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/t")
public class Rest3 {
	public Rest3() {
		System.out.println("实例化 Rest3()");
	}
	
	    //访问路径 /h/text/name123
	    @GET
	    @Path("text/{name}")
	    @Produces(MediaType.TEXT_PLAIN) 
	    public String hello(@PathParam("name") String name) throws Exception {
	    	System.out.println("/text/{name}");
	        return "hello, " + name;
	    }

	    //访问路径 /hello/json/name123
	    @GET
	    @Path("/json/{name}")
	    // @Consumes(MediaType.APPLICATION_JSON) // 声明传入参数是json格式
	    @Produces(MediaType.APPLICATION_JSON)// 声明这个接口将以json格式返回
	    public String hello2(@PathParam("name") String name) throws Exception {
	        return "hello, " + name;
	    }

	    //访问路径 /hello/xml/name123
	    @GET
	    @Path("/xml/{name}")
	    @Produces(MediaType.APPLICATION_XML)
	    public String hello3(@PathParam("name") String name) throws Exception {
	        return "hello, " + name;
	    }
}
